﻿using System;
using System.Web.Mvc;
using sBlog.Net.Domain.Entities;
using sBlog.Net.Domain.Interfaces;

namespace sBlog.Net.Areas.Admin.Controllers
{
    public class SplashAdminController : Controller
    {
        private readonly IUser _userRepository;
        //
        // GET: /Admin/SplashAdmin/
        public SplashAdminController(IUser userRepository)
        {
            _userRepository = userRepository;
        }

        [Authorize]
        public ActionResult ManageSplash()
        {
            UserEntity user = _userRepository.GetUserObjByUserID(GetUserId());
            return View(user);
        }

        [HttpPost]
        public ActionResult ManageSplash(string splash)
        {
            _userRepository.UpdateSplash(GetUserId(), splash);
            return View("ManageSplash");
        }

        protected int GetUserId()
        {
            var userId = -1;
            if (Request.IsAuthenticated)
            {
                var userIdentity = (IUserInfo)User.Identity;
                userId = Int32.Parse(userIdentity.UserId);
            }
            return userId;
        }
    }
}
